package com.cloudfun.campusshare.controller;

import com.cloudfun.campusshare.common.response.BaseResult;
import com.cloudfun.campusshare.common.response.BaseResultFactory;
import com.cloudfun.campusshare.common.security.AuthRequired;
import com.cloudfun.campusshare.service.BsAreaService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.Builder;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Pageable;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author : zhangyongjie
 * @version : 1.0
 * @createTime : 2021/3/29 15:39
 * @description :
 */
@RestController
@RequestMapping("/v1/area")
@Api(value = "地区列表")
@Validated
@Slf4j
@AuthRequired
@Builder
public class BsAreaController {

    private BsAreaService bsAreaService;

    @GetMapping("/list")
    @ApiOperation(value = "获取地区列表（前端查询）")
    BaseResult<?> getAreaList(Pageable pageable, @ApiParam(value = "关键字",required = false) @RequestParam(required = false) String keyword,
                              @ApiParam(value = "等级地区级别（1:省份province,2:市city,3:区县district,4:街道street）") @RequestParam Integer level,
                              String parentCode){
        return BaseResultFactory.produceSuccess(bsAreaService.queryAreaList(pageable, keyword, level, parentCode));

    }
}
